package chapter10;

import java.util.Calendar;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author liuziyang
 * @create 2019-02-13 13:23
 */
public class CalendarTest {
    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        System.out.println("year:" + calendar.get(Calendar.YEAR));
        System.out.println("month:" + calendar.get(Calendar.MONTH));
        System.out.println("day:" + calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println("hour:" + calendar.get(Calendar.HOUR_OF_DAY));
        System.out.println("minute:" + calendar.get(Calendar.MINUTE));
        System.out.println("second:" + calendar.get(Calendar.SECOND));

        System.out.println("milliscond:" + calendar.get(Calendar.MILLISECOND));
        System.out.println("weekday:" + calendar.get(Calendar.DAY_OF_WEEK));

        calendar.add(Calendar.DATE, 24);
        System.out.println(calendar.get(Calendar.DATE));

        printCalendar(calendar);

        Date date = calendar.getTime();
        System.out.println(date.toString());
    }

    private static void printCalendar(Calendar calendar) {
        StringBuilder builder = new StringBuilder();
        builder.append(calendar.get(Calendar.YEAR)).append("-");
        builder.append(calendar.get(Calendar.MONTH) + 1).append("-");
        builder.append(calendar.get(Calendar.DAY_OF_MONTH)).append(" ");
        builder.append(calendar.get(Calendar.HOUR_OF_DAY)).append(":");
        builder.append(calendar.get(Calendar.MINUTE)).append(":");
        builder.append(calendar.get(Calendar.SECOND));

        System.out.println(builder.toString());
    }
}
